
const serverUrl="http://test.udcloth.net"  




function getOptions(_path,method,req){
  var Authorization = req.headers['authorization']
  var options = {
    method: method||'GET',
    url: serverUrl+_path,
    headers: {
      'User-Agent': 'request',
      'authorization':Authorization,
      'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
    },
  }
  if(method === 'POST'){
    options.formData = req.body
  }
  return options
}

function getJsonOptions(_path,req,body){
  console.log(serverUrl+_path)
  var token = req.headers['token']
  console.log('============'+body)
  if(body && typeof body == 'string'){
    body = JSON.parse(body)
  }
  var options = {
    method: 'POST',
    url: serverUrl+_path,
    headers: {
      'Content-Type': 'application/json',
      'token':token
    },
    body:body,
    json: true
  }
  // console.log(body)
  // console.log(options)
  return options
}




const lib = {
  token:'',
  url : serverUrl,
  getOptions : getOptions,
  getJsonOptions :getJsonOptions
}

module.exports=lib

